package 树;

import java.util.LinkedList;
import java.util.Queue;

public class Demo05 {
    public static void main(String[] args) {
        Queue<Node> queue = new LinkedList<>();
        queue.isEmpty();
        queue.poll();
        System.out.println(queue.size());


        System.out.println(queue.isEmpty());
    }


    /*
    * 解法一: 常规的层序遍历
    * */
    static class Solution {
        public Node connect(Node root) {
            Queue<Node> queue = new LinkedList<>();
            queue.add(root);
            int curNum = 1;
            int nextNum = 0;

            while(!queue.isEmpty()){
                Node preNode = null;
                while(curNum > 0){
                    System.out.println(1);
                    Node cur = queue.poll();

                    if(preNode != null){
                        preNode.next = cur;
                    }
                    preNode = cur;


                    if(cur.left != null){
                        queue.add(cur.left);
                        nextNum++;
                    }
                    if(cur.right != null){
                        queue.add(cur.right);
                        nextNum++;
                    }
                    curNum--;
                }
                curNum = nextNum;
                nextNum = 0;
            }
            return root;
        }
    }
}
